﻿Vue.prototype.fileMap = new Map([
    ['mp4', 'video/mp4'],
    ['avi', 'video/avi'],
    ['webm', 'video/webm'],
    ['jpg', 'image/jpg'],
    ['jpeg', 'image/jpeg'],
    ['png', 'image/png'],
]);

Vue.prototype.getVueFile = async function (url, fileName) {
    var vueFileObj;
    await axios({
        method: "post",
        url: url, //后端下载接口地址
        responseType: "blob",  // 设置接受的流格式
        data: {
            fileName: fileName
        },
    }).then((res) => {
        let blob = new Blob([res.data], { type: "application/octet-stream" });

        var fileExt = fileName.substring(fileName.lastIndexOf('.') + 1);
        const fileObj = new File([blob], fileName, {
            type: this.fileMap.get(fileExt),
        });

        vueFileObj = { raw: fileObj };
    }, error => {
        alert("错误提示：" + error.message);
    });

    return vueFileObj;
}